home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 June / Software of the Month Club 1996 June.iso / pc / dos / dtp / display / util / sbvol.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-06  |  2.1 KB  |  73 lines

  1. /*
  2.   Set sound blaster volume
  3.  
  4.   Written by Jih-Shin Ho, 1995
  5. */
  6.     
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <dos.h>
  10.  
  11. #define SB_MIXER_ADDRESS    0x04    /* Pro+ only */
  12. #define SB_MIXER_DATA        0x05    /* Pro+ only */
  13.  
  14. /* For SB16 only. Left first, then Right */
  15. #define SB_MASTER_VOL_16 0x30               
  16. #define SB_DIGITAL_VOL_16 0x32
  17. #define SB_FM_VOL_16 0x34
  18. #define SB_CD_VOL_16 0x36
  19.  
  20. static unsigned int sb_ioaddr = 0x220;
  21.  
  22. static void set_volume(unsigned int vol_addr,unsigned int volume)
  23. {
  24.   if (volume > 31) volume = 31;
  25.   outportb(sb_ioaddr + SB_MIXER_ADDRESS,vol_addr);         /* L */
  26.   outportb(sb_ioaddr + SB_MIXER_DATA,volume << 3);
  27.   outportb(sb_ioaddr + SB_MIXER_ADDRESS,vol_addr + 1);     /* R */
  28.   outportb(sb_ioaddr + SB_MIXER_DATA,volume << 3);
  29. }
  30.  
  31.  
  32. static void usage(void)
  33. {
  34.   printf("\nSet Sound Blaster 16 volume.\n");
  35.   printf("sbvol -a <address> (-c|-w|-m|-f) <volume>\n"
  36.          "  <address> : Sound Blaster 16 I/O address, default is 220H\n"
  37.          "  -c,-w,-m,-f : For CD, Wave, Master, FM(MIDI) volume\n"
  38.          "  <volume> : sound volume. 0 .. 31\n");
  39. }
  40.  
  41.  
  42. int main(int argc,char *argv[])
  43. {
  44.   int index,cd_vol,wav_vol,mas_vol,fm_vol,id;
  45.  
  46.   if (argc == 1) { usage(); return(0); }
  47.  
  48.   cd_vol = wav_vol = mas_vol = fm_vol = -1;
  49.   for (index = 1; index < argc; ++index) {
  50.     if (argv[index][0] != '-') { usage(); return(1); }
  51.     id = argv[index][1]; index++;
  52.     switch (id) {
  53.       case 'a': case 'A':
  54.         sb_ioaddr = atoi(argv[index]); break;
  55.       case 'c': case 'C':
  56.         cd_vol = atoi(argv[index]); break;
  57.       case 'w': case 'W':
  58.         wav_vol = atoi(argv[index]); break;
  59.       case 'm': case 'M':
  60.         mas_vol = atoi(argv[index]); break;
  61.       case 'f': case 'F':
  62.         fm_vol = atoi(argv[index]); break;
  63.       default:
  64.         usage(); return(1);
  65.     }
  66.   }
  67.   if (cd_vol >= 0) set_volume(SB_CD_VOL_16,cd_vol);
  68.   if (wav_vol >= 0) set_volume(SB_DIGITAL_VOL_16,wav_vol);
  69.   if (mas_vol >= 0) set_volume(SB_MASTER_VOL_16,mas_vol);
  70.   if (fm_vol >= 0) set_volume(SB_FM_VOL_16,fm_vol);
  71.   return(0);
  72. }
  73.